﻿Imports MySql.Data.MySqlClient
Public Class Form1
    Inherits DevExpress.XtraEditors.XtraForm
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim loginForm As FormTester
        DevExpress.Skins.SkinManager.EnableFormSkins()
        DevExpress.UserSkins.BonusSkins.Register()
        DevExpress.UserSkins.OfficeSkins.Register()
        Me.LookAndFeel.SkinName = "Office 2010 Blue"
        DefaultLookAndFeel1.LookAndFeel.SkinName = "Office 2010 Blue"
        Dim mainForm As New FormTester
        mainForm.Hide()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim conn As New MySqlConnection
        Dim myCommand As New MySqlCommand
        Dim myCommand2 As New MySqlCommand
        Dim myConnString As String
        'Dim UserID As String

        myConnString = "server=localhost;User Id=root;password=;Persist Security Info=True;database=db_petruk_new"

        conn.ConnectionString = myConnString


        conn.Open()

        myCommand.Connection = conn
        myCommand2.Connection = conn
        myCommand.CommandText = "SELECT * FROM master_user WHERE USERNAME = '" & TextBox1.Text & "' AND PASSWORD = '" & TextBox2.Text & "' AND ROLE = 'Admin'"
        myCommand2.CommandText = "SELECT * FROM master_user WHERE USERNAME = '" & TextBox1.Text & "' AND PASSWORD = '" & TextBox2.Text & "' AND ROLE = 'Kepala Dinas'"
        Dim dt = New DataTable()
        Dim dt2 = New DataTable()
        Dim ds = New MySqlDataAdapter(myCommand)
        Dim ds2 = New MySqlDataAdapter(myCommand2)

        ds.Fill(dt)
        ds2.Fill(dt2)
        If (dt.Rows.Count > 0) Then
            'conn.Close()
            Me.Hide()
            FormTester.Show()
        ElseIf (dt2.Rows.Count > 0) Then
            Me.Hide()
            FormTester.Show()
            FormTester.MasterMenuToolStripMenuItem.Visible = False
        Else
            MsgBox("Username atau Password tidak cocok. Silahkan coba lagi", MsgBoxStyle.Critical, "Notifikasi")
        End If
    End Sub
End Class